<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.js"></script>
    <style>
        textarea{
            width: 300px;
            height: 300px;
        }
    </style>
</head>
<body>
    <textarea id="input">

    </textarea>
    </br>
    <button id="send">发送</button>

    </br>
    <textarea id="output">

    </textarea>

    <script>
        var socket = new WebSocket("ws://localhost:8000/ws")

        $("#send").click(function(){
            socket.send($("#input").val())
        })

        socket.onopen = function(event){
            $("#output").text("连接服务器成功")
        }

        socket.onmessage = function(event){
            $("#output").text(
                $("#output").text() + "\r\n" + event.data
            )
        }

        socket.onclose = function(event){
            $("#output").text("与服务器断开连接")
        }
    </script>
</body>
</html>